/**
 * weapp-js v1.7.1(2021-4-16)
 * https://codeup.aliyun.com/motigo/motigo/weapp_base
 * Copyright@ 2021 Motigo, Inc.
 * 
 */
//  锁机制模块

export class basicLock {
    /*
        锁机制

        功能描述：
            提供最基本的锁行为：
            - 加锁
            - 解锁
            - 查看是否锁住
    */
    constructor(){
        this.ENUM = {
            "UNLOCK":"UNLOCK",
            "LOCKED":"LOCKED",
        }
        this.state = this.ENUM.UNLOCK
    }

    lock(){
        /*
            加锁操作
        */
        let res = false;
        if(this.state == this.ENUM.UNLOCK){
            this.state = this.ENUM.LOCKED
            res = true
        }
        return res
    }

    unlock(){
        /*
            解锁操作
        */
        let res = false;
        if(this.state == this.ENUM.LOCKED){
            this.state = this.ENUM.UNLOCK
            res = true
        }
        return res
    }

    isLocked(){
        /*
            判断是否锁上
        */
        return this.state == this.ENUM.LOCKED
    }
}
